<template>
<div>
  <NavBar>
  用户中心
  </NavBar>
  <div class="userInfo">
    <div style="float: left">
    <van-image
        width="5rem"
        height="5rem"
        fit="contain"
        :src="list.avatar_url"
    />
  </div>
    <div style="float:left;text-align: left;margin-left: 10px;font-size: 14px">
        <p>昵称:  {{list.name}}</p>
        <p>登录名:  {{list.email}}</p>
        <p>个性签名:  成就自己的只需一套精品</p>
    </div>
  </div>
  <div class="myList">
    <ul>
      <li @click="goTo('/collect')">
        <span>我的收藏</span>
        <van-icon name="arrow"/>
      </li>
      <li @click="goTo('/order')">
        <span>我的订单</span>
        <van-icon name="arrow"/>
      </li>
      <li @click="goTo('/setting')">
        <span>账号管理</span>
        <van-icon name="arrow"/>
      </li>
      <li @click="goTo('/address')">
        <span>地址管理</span>
        <van-icon name="arrow"/>
      </li>
      <li @click="goTo('/about')">
        <span>关于我们</span>
        <van-icon name="arrow"/>
      </li>
    </ul>
  </div>
  <van-button class="btn" type="info" @click="toLogOut" round>退出登录</van-button>
</div>
</template>

<script>
import NavBar from "@/components/common/navbar";
import {getCurrentInstance,onMounted,ref,reactive,toRefs} from 'vue'
import {useRouter} from 'vue-router'
import {Toast} from 'vant'
import {useStore} from 'vuex'
export default {
  name: "index",
  components: {NavBar},
  setup(){
    const router=useRouter()
    const {proxy}=getCurrentInstance()
    const store=useStore()
    onMounted(()=>{
      getUserInfo()
    })
    let user=reactive({
      list:{}
    })
    const getUserInfo=async ()=>{
      await proxy.$API.user.getUser().then(res=>{
        console.log(res)
        user.list=res
        console.log('user',user)
      })
    }
    const goTo=(path,query)=>{
      router.push({
        path:path,
        query:query||{}
      })
    }
   const toLogOut=()=>{
      proxy.$API.user.LogOut().then(res=>{
        console.log(res)
        if(res.status=='204'){
          Toast('退出登录成功')
          window.localStorage.setItem('token','')
          store.commit('setUseInfo',false)
          setTimeout(()=>{
            router.push({
              path:'/login'
            })
          },500)
        }
      })
    }
    return{
      toLogOut,
      ...toRefs(user),
      goTo
    }
  }
}
</script>

<style scoped>
.userInfo{
  color: white;
  padding:20px 0;
  background-color: 	#7FFFD4;
  text-align: center;
  margin: 70px 10px 0 10px;
  border-radius: 4px;
  display: flex;
  justify-content: center;
  align-items: center;
}
.btn{
  margin-top: 20px;
  margin-left: 40px;
  width: 300px;
  background-color:#42b983;
  border: none;
  color: white;
}
.myList{
  margin-top:10px;
  color: #000000d9;
  font-weight: 500;
  background: #f0f0f0;
}
.myList li{
  padding:10px 20px;
  background-color: white;
}
.myList li:nth-child(2n+1){
  margin-top: 15px;
}
.van-icon{
  float: right;
}
</style>
